package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders order);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

   @Delete("delete from orders where id = #{orderId}")
    void deleteById(Long orderId);

 Page<Orders> page(OrdersPageQueryDTO ordersPageQueryDTO);

@Select("select * from orders where user_id = #{userId}")
List<Orders> getByUserId(Long userId);
@Select("select * from orders where id = #{id}")
    Orders getById(Long id);
     @Select("select count(*) from orders where status=3")
    Integer countConfirmedStatus();
    @Select("select count(*) from orders where status=4")
    Integer countDeliveryInProgressStatus();
    @Select("select count(*) from orders where status=2")
    Integer countToBeConfirmedStatus();

    @Select("select *from orders where status=#{status} and order_time<#{ordertime}")
   List<Orders> getStatusAndOrderTimeLt(Integer status, LocalDateTime ordertime);
    @Select("select *from orders where status=#{deliveryInProgress}")
    List<Orders> getDeliveryOrders(Integer deliveryInProgress);

    Double getAmountByLocalDate(LocalDateTime date1, LocalDateTime date2);

    Integer countSumByLocalDate(LocalDateTime date1, LocalDateTime date2);

    Integer countValidOrderCountByLocalDate(LocalDateTime date1, LocalDateTime date2);

//    @MapKey("b.name")
//   List<Map<String,String>> getTop10NamesAndNumbersByLocalDate(LocalDateTime date1, LocalDateTime date2);


    List<GoodsSalesDTO> getTop10NamesAndNumbersByLocalDate(LocalDateTime date1, LocalDateTime date2);

    /**
     * 以下两个是老师写的
     * @param map
     * @return
     */
    Integer countByMap(Map map);
    Double sumByMap(Map map);
}
